{
  "properties" : { },
  "id" : "2a4ccbf520d74571b03ed3b81f5b7326",
  "script" : null,
  "groupId" : "43da313fdeaa495798cf783e6cf83479",
  "name" : "ip使用情况统计",
  "createTime" : 1727070841958,
  "updateTime" : 1726303052282,
  "lock" : "1",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "countStatics",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\"ipType\":32,\"groupId\":\"cba03f89025a42f9bf6a3c191eaed231\"}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"status\": 200,\n    \"message\": \"success\",\n    \"data\": {\n        \"total\": \"7680\",\n        \"ysy\": \"611\",\n        \"wsy\": \"7069\",\n        \"lv\": \"7.96\",\n        \"childrenReal\": [\n            {\n                \"startIp\": \"61.100.0.0\",\n                \"total\": 65536,\n                \"wsy\": 65536,\n                \"stopIp\": \"61.100.255.255\",\n                \"ysy\": 0\n            }\n        ],\n        \"childrenNonReal\": [\n            {\n                \"startIp\": \"61.101.0.0\",\n                \"total\": 65536,\n                \"wsy\": 65536,\n                \"stopIp\": \"61.101.255.255\",\n                \"ysy\": 0\n            }\n        ]\n    }\n}",
  "description" : "",
  "requestBodyDefinition" : {
    "name" : "root",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "groupId",
      "value" : "18ac461de04346c78bf459a881a03ab3",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "ipType",
      "value" : "32",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "status",
      "value" : "200",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "success",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ {
        "name" : "total",
        "value" : "4",
        "description" : "",
        "required" : false,
        "dataType" : "String",
        "type" : "",
        "defaultValue" : "",
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ ]
      }, {
        "name" : "ysy",
        "value" : "0",
        "description" : "",
        "required" : false,
        "dataType" : "String",
        "type" : "",
        "defaultValue" : "",
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ ]
      }, {
        "name" : "wsy",
        "value" : "4",
        "description" : "",
        "required" : false,
        "dataType" : "String",
        "type" : "",
        "defaultValue" : "",
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ ]
      } ]
    } ]
  }
}
================================
import com.google.gson.JsonObject
// import org.springblade.common.exception.BusinessException;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal
import java.math.RoundingMode
import com.alibaba.fastjson.JSONArray
import org.springframework.util.CollectionUtils

import redis

import "@/util/getGroupIdList" as getGroupIdList;

/**
 * 管理地址 掩码
 */
var MANAGE_MASK = "32";
/**
 * 互联地址 掩码
 */
var NET_MASK = "30";
/**
 * 应用地址 掩码
 */
var APP_MASK = "26";

String groupId = body.groupId;
if (StringUtils.isEmpty(groupId)) {
    return "请先选择分组";
}
//ip类型，32-管理，30-互联，26-应用
String ipType = body.ipType;

//查询该分组下的子分组
List listGroupId = getGroupIdList(groupId);
if (CollectionUtils.isEmpty(listGroupId)) {
     return "请先选择分组2" ;
}
var res = db.selectOne("""
   SELECT COUNT
               ( 1 ) total,
               SUM ( usage_status ) ysy,
               SUM ( CASE WHEN usage_status = 0 THEN 1 ELSE 0 END ) wsy
        FROM
            ndmp_ip_source_manager
        WHERE ip_type = #{ipType}
        
         and  group_id in
            <foreach collection="listGroupId" index="index" item="id" open="(" close=")" separator=",">
                #{id}
            </foreach>
        
        
 """)
BigDecimal total = new BigDecimal(String.valueOf(res.get("total")));
if (res.get("ysy") != 0 && res.get("ysy") != null) {
    BigDecimal used = new BigDecimal(String.valueOf(res.get("ysy")));
    BigDecimal usedRate = used.divide(total, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))
        .setScale(2, RoundingMode.HALF_UP);
    res.put("lv", String.valueOf(usedRate));
}

List children = new ArrayList();

var pointObject = null;

if (MANAGE_MASK.equals(ipType)) {
    pointObject = redis.getPoint(groupId, "manager");

} else if (NET_MASK.equals(ipType)) {
    pointObject = redis.getPoint(groupId, "net");
} else {
    pointObjectRt = redis.getPoint(groupId, "appRealTime");

    if (null != pointObjectRt) {
        List childrenReal = new ArrayList();
        Map map = pointObjectRt.getValue();
        String str = map.get("0");
        childrenReal = JSONArray.parseArray(str, Map.class);
        res.put("childrenReal", childrenReal);
    }



    PointObject pointObjectNrt = redis.getPoint(groupId, "appNonRealTime");
    if (null != pointObjectNrt) {
        List childrenNonReal = new ArrayList();
        Map map = pointObjectNrt.getValue();
        String str = map.get("0");
        childrenNonReal = JSONArray.parseArray(str, Map.class);
        res.put("childrenNonReal", childrenNonReal);
    }

}

if (null != pointObject) {
    Map map = pointObject.getValue();
    String str = map.get("0");
    children = JSONArray.parseArray(str, Map.class);
    res.put("children", children);
}
return res;